package cn.remex.wechat.beans.xmlmessages;

import org.dom4j.Document;
import org.dom4j.DocumentHelper;
import org.dom4j.Element;

import java.util.List;

/**
 * Created by gqy on 16-6-2.
 */
public class XMLNewsMessage {
    private String toUser;
    private List<Article> articles;

    private Element re;

    public XMLNewsMessage(Element re,List<Article> articles) {
        this.articles = articles;
        this.re=re;
    }

    public Element getRe() {
        re.addElement("MsgType").addText("news");
        re.addElement("ArticleCount").addText(String.valueOf(articles.size()));
        Element ele = DocumentHelper.createElement("Articles");
        for(Article a : articles){
            Element element = DocumentHelper.createElement("item");
            element.addElement("Title").addText(a.getTitle()==null?"":a.getTitle());
            element.addElement("Description").addText(a.getDescription()==null?"":a.getDescription());
            element.addElement("PicUrl").addText(a.getPicurl()==null?"":a.getPicurl());
            element.addElement("Url").addText(a.getUrl()==null?"":a.getUrl());
            ele.add(element);
        }
        re.add(ele);
        return re;
    }

    //消息
    public static class Article {
        private String title;
        private String description;
        private String url;
        private String picurl;

        public String getDescription() {
            return description;
        }

        public void setDescription(String description) {
            this.description = description;
        }

        public String getPicurl() {
            return picurl;
        }

        public void setPicurl(String picurl) {
            this.picurl = picurl;
        }

        public String getTitle() {
            return title;
        }

        public void setTitle(String title) {
            this.title = title;
        }

        public String getUrl() {
            return url;
        }

        public void setUrl(String url) {
            this.url = url;
        }
    }
}
